﻿using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using TianShiProject.Models;
using TianShiProject.Models.BaseInfo;
using TianShiProject.Models.CarService;
using TianShiProject.Models.Common;
using TianShiProject.Models.Contract;
using TianShiProject.Models.HumanAffairs;
using TianShiProject.Models.Materials.NewLibrarys;
using TianShiProject.Models.SettleAccounts.PaymentApplys;
using TianShiProject.Models.Materials.PurchaseRequests;
using TianShiProject.Models.Materials.RecipientsToAppls;
using TianShiProject.Models.Materials.SelectedItemss;
using TianShiProject.Models.NewSalesInvoices;
using TianShiProject.Models.SettleAccounts;
using TianShiProject.Models.System;
using Volo.Abp.AuditLogging.EntityFrameworkCore;
using Volo.Abp.BackgroundJobs.EntityFrameworkCore;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.FeatureManagement.EntityFrameworkCore;
using Volo.Abp.Identity;
using Volo.Abp.Identity.EntityFrameworkCore;
using Volo.Abp.IdentityServer.EntityFrameworkCore;
using Volo.Abp.PermissionManagement.EntityFrameworkCore;
using Volo.Abp.SettingManagement.EntityFrameworkCore;
using Volo.Abp.TenantManagement;
using Volo.Abp.TenantManagement.EntityFrameworkCore;
using TianShiProject.Models.Shen.OwnerContracts;
using TianShiProject.Models.Shen.TransportContracts;
using TianShiProject.Models.Shen.GeneralContracts;
using TianShiProject.Models.Test;
using TianShiProject.Models.Materials.Citys;
using TianShiProject.Models.Shen.LiZhiShens;
using TianShiProject.Models.Shen.PaymentShens;
using TianShiProject.Models.Shen.RecipientShens;
using TianShiProject.Models.Shen.RequestShens;
using TianShiProject.Models.Shen.RuZhiShens;
using TianShiProject.Models.Shen.ZhuanZhengShens;
using TianShiProject.Models.Materials.MaterialStatistics;

namespace TianShiProject.EntityFrameworkCore
{
    [ReplaceDbContext(typeof(IIdentityDbContext))]
    [ReplaceDbContext(typeof(ITenantManagementDbContext))]
    [ConnectionStringName("Default")]
    public class TianShiProjectDbContext : 
        AbpDbContext<TianShiProjectDbContext>,
        IIdentityDbContext,
        ITenantManagementDbContext
    {
        /* Add DbSet properties for your Aggregate Roots / Entities here. */
        
        #region Entities from the modules
        
        /* Notice: We only implemented IIdentityDbContext and ITenantManagementDbContext
         * and replaced them for this DbContext. This allows you to perform JOIN
         * queries for the entities of these modules over the repositories easily. You
         * typically don't need that for other modules. But, if you need, you can
         * implement the DbContext interface of the needed module and use ReplaceDbContext
         * attribute just like IIdentityDbContext and ITenantManagementDbContext.
         *
         * More info: Replacing a DbContext of a module ensures that the related module
         * uses this DbContext on runtime. Otherwise, it will use its own DbContext class.
         */
        
        //Identity
        public DbSet<IdentityUser> Users { get; set; }
        public DbSet<IdentityRole> Roles { get; set; }
        public DbSet<IdentityClaimType> ClaimTypes { get; set; }
        public DbSet<OrganizationUnit> OrganizationUnits { get; set; }
        public DbSet<IdentitySecurityLog> SecurityLogs { get; set; }
        public DbSet<IdentityLinkUser> LinkUsers { get; set; }
        
        // Tenant Management
        public DbSet<Tenant> Tenants { get; set; }
        public DbSet<TenantConnectionString> TenantConnectionStrings { get; set; }


        /// <summary>
        /// 系统管理
        /// </summary>
        public DbSet<Company> companys { get; set; }
        public DbSet<Department> departments { get; set; }
        public DbSet<Menu> menus { get; set; }
        public DbSet<Operator> operators { get; set; }
        public DbSet<ORRelation> oRRelations { get; set; }
        public DbSet<Position> positions { get; set; }
        public DbSet<RMRelation> rMRelations { get; set; }
        public DbSet<Role> roles { get; set; }
        /// <summary>
        /// 结算管理
        /// </summary>
        /// <param name="options"></param>
        public DbSet<NewExpensesPayab> newExpensesPayabs { get; set; }
        public DbSet<NewExpensesRecei> newExpensesReceis { get; set; }
        public DbSet<NewInputInvoice> newInputInvoices { get; set; }
        public DbSet<NewSalesInvoice> newSalesInvoices { get; set; }
        /// <summary>
        /// 物资管理
        /// </summary>
        /// <param name="options"></param>
        public DbSet<NewLibrary> newLibraries { get; set; }
        public DbSet<PaymentApply> paymentApplies { get; set; }
        public DbSet<PurchaseRequest> purchaseRequests { get; set; }
        public DbSet<RecipientsToAppl> recipientsToAppls { get; set; }
        public DbSet<SelectedItems> selectedItems { get; set; }
        public DbSet<Country> countrys { get; set; }
        public DbSet<MaterialStatistics> materialStatistics { get; set; }
        /// <summary>
        /// 人事管理
        /// </summary>
        /// <param name="options"></param>
        public DbSet<Base> bases { get; set; }
        public DbSet<Entry> entries { get; set; }
        public DbSet<Job> jobs { get; set; }
        public DbSet<Leave> leaves { get; set; }
        public DbSet<Promotion> promotions { get; set; }
        /// <summary>
        /// 合同管理
        /// </summary>
        /// <param name="options"></param>
        public DbSet<NewGeneralContra> newGeneralContras { get; set; }
        public DbSet<NewOwnerContract> newOwnerContracts { get; set; }
        public DbSet<NewTransportCont> newTransportConts { get; set; }
        /// <summary>
        /// 公共
        /// </summary>
        /// <param name="options"></param>
        public DbSet<Dictionary> dictionaries { get; set; }
        public DbSet<ProcedureListShen> procedureListShens { get; set; }
        public DbSet<ProcedureNodeShen> procedureNodeShens { get; set; }
        public DbSet<ProcedureLogShen> procedureLogShens { get; set; }
        /// <summary>
        /// 车辆服务管理
        /// </summary>
        /// <param name="options"></param>
        public DbSet<Accident> accidents { get; set; }
        public DbSet<Illegal> illegals { get; set; }
        public DbSet<Maintain> maintains { get; set; }
        public DbSet<Pay> pays { get; set; }
        public DbSet<Tyre> tyres { get; set; }
        public DbSet<Upkeep> upkeeps { get; set; }
        /// <summary>
        /// 基本信息
        /// </summary>
        /// <param name="options"></param>
        public DbSet<Car> cars { get; set; }
        public DbSet<Line> lines { get; set; }
        public DbSet<OilCost> oilCosts { get; set; }
        public DbSet<Outsource> outsources{ get; set; }
        public DbSet<Owner> owners { get; set; }

        /// <summary>
        /// 审批管理
        /// </summary>
        /// <param name="options"></param>
        public DbSet<OwnerContractShen> ownerContractShens { get; set; }
        public DbSet<GeneralContractShen> generalContractShens { get; set; }
        public DbSet<TransportContractShen> transportContractShens { get; set; }
        public DbSet<LiZhiShen> liZhiShens { get; set; }
        public DbSet<PaymentShen> paymentShens { get; set; }
        public DbSet<RecipientShen> recipientShens { get; set; }
        public DbSet<RequestShen> requestShens { get; set; }
        public DbSet<RuZhiShen> ruZhiShens { get; set; }
        public DbSet<ZhuanZhengShen> zhuanZhengShens { get; set; }

        #endregion

        public TianShiProjectDbContext(DbContextOptions<TianShiProjectDbContext> options)
            : base(options)
        {

        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            /* Include modules to your migration db context */

            builder.ConfigurePermissionManagement();
            builder.ConfigureSettingManagement();
            builder.ConfigureBackgroundJobs();
            builder.ConfigureAuditLogging();
            builder.ConfigureIdentity();
            builder.ConfigureIdentityServer();
            builder.ConfigureFeatureManagement();
            builder.ConfigureTenantManagement();

            /* Configure your own tables/entities inside here */

            //builder.Entity<YourEntity>(b =>
            //{
            //    b.ToTable(TianShiProjectConsts.DbTablePrefix + "YourEntities", TianShiProjectConsts.DbSchema);
            //    b.ConfigureByConvention(); //auto configure for the base class props
            //    //...
            //});
           //系统管理
            builder.Entity<Company>(b =>
            {
                b.ToTable("Company");
            });
            builder.Entity<Department>(b =>
            {
                b.ToTable("Department");
            });
            builder.Entity<Menu>(b =>
            {
                b.ToTable("Menu");
            });
            builder.Entity<Operator>(b =>
            {
                b.ToTable("Operator");
            });
            builder.Entity<ORRelation>(b =>
            {
                b.ToTable("ORRelation");
            });
            builder.Entity<Position>(b =>
            {
                b.ToTable("Position");
            });
            builder.Entity<RMRelation>(b =>
            {
                b.ToTable("RMRelation");
            });
            builder.Entity<Role>(b =>
            {
                b.ToTable("Role");
            });
            //结算管理
            builder.Entity<NewExpensesPayab>(b =>
            {
                b.ToTable("NewExpensesPayab");
            });
            builder.Entity<NewExpensesRecei>(b =>
            {
                b.ToTable("NewExpensesRecei");
            });
            builder.Entity<NewInputInvoice>(b =>
            {
                b.ToTable("NewInputInvoice");
            });
            builder.Entity<NewSalesInvoice>(b =>
            {
                b.ToTable("NewSalesInvoice");
            });
            //物资管理
            builder.Entity<NewLibrary>(b =>
            {
                b.ToTable("NewLibrary");
            });
            builder.Entity<PaymentApply>(b =>
            {
                b.ToTable("PaymentApply");
            });
            builder.Entity<PurchaseRequest>(b =>
            {
                b.ToTable("PurchaseRequest");
            });
            builder.Entity<RecipientsToAppl>(b =>
            {
                b.ToTable("RecipientsToAppl");
            });
            builder.Entity<SelectedItems>(b =>
            {
                b.ToTable("SelectedItems");
            });
            builder.Entity<Country>(b =>
            {
                b.ToTable("Country");
            });
            builder.Entity<MaterialStatistics>(b =>
            {
                b.ToTable("MaterialStatistics");
            });
            //人事管理
            builder.Entity<Base>(b =>
            {
                b.ToTable("Base");
            });
            builder.Entity<Entry>(b =>
            {
                b.ToTable("Entry");
            });
            builder.Entity<Job>(b =>
            {
                b.ToTable("Job");
            });
            builder.Entity<Leave>(b =>
            {
                b.ToTable("Leave");
            });
            builder.Entity<Promotion>(b =>
            {
                b.ToTable("Promotion");
            });
            //合同管理
            builder.Entity<NewGeneralContra>(b =>
            {
                b.ToTable("NewGeneralContra");
            });
            builder.Entity<NewOwnerContract>(b =>
            {
                b.ToTable("NewOwnerContract");
            });
            builder.Entity<NewTransportCont>(b =>
            {
                b.ToTable("NewTransportCont");
            });
            //公共
            builder.Entity<Dictionary>(b =>
            {
                b.ToTable("Dictionary");
            });
           
            builder.Entity<ProcedureListShen>(b =>
            {
                b.ToTable("ProcedureListShen");
            });
            builder.Entity<ProcedureNodeShen>(b =>
            {
                b.ToTable("ProcedureNodeShen");
            });
            builder.Entity<ProcedureLogShen>(b =>
            {
                b.ToTable("ProcedureLogShen");
            });

            //车辆服务管理
            builder.Entity<Accident>(b =>
            {
                b.ToTable("Accident");
            });
            builder.Entity<Illegal>(b =>
            {
                b.ToTable("Illegal");
            });
            builder.Entity<Maintain>(b =>
            {
                b.ToTable("Maintain");
            });
            builder.Entity<Pay>(b =>
            {
                b.ToTable("Pay");
            });
            builder.Entity<Tyre>(b =>
            {
                b.ToTable("Tyre");
            });
            builder.Entity<Upkeep>(b =>
            {
                b.ToTable("Upkeep");
            });
            //基本信息
            builder.Entity<Car>(b =>
            {
                b.ToTable("Car");
            });
            builder.Entity<Line>(b =>
            {
                b.ToTable("Line");
            });
            builder.Entity<OilCost>(b =>
            {
                b.ToTable("OilCost");
            });
            builder.Entity<Outsource>(b =>
            {
                b.ToTable("Outsource");
            });
            builder.Entity<Owner>(b =>
            {
                b.ToTable("Owner");
            });
            //审批管理
            builder.Entity<OwnerContractShen>(b =>
            {
                b.ToTable("OwnerContractShen");
            });
            builder.Entity<TransportContractShen>(b =>
            {
                b.ToTable("TransportContractShen");
            });
            builder.Entity<GeneralContractShen>(b =>
            {
                b.ToTable("GeneralContractShen");
            });
            builder.Entity<RecipientShen>(b =>
            {
                b.ToTable("RecipientShen");
            });
            builder.Entity<RequestShen>(b =>
            {
                b.ToTable("RequestShen");
            });
            builder.Entity<RuZhiShen>(b =>
            {
                b.ToTable("RuZhiShen");
            });
            builder.Entity<LiZhiShen>(b =>
            {
                b.ToTable("LiZhiShen");
            });
            builder.Entity<ZhuanZhengShen>(b =>
            {
                b.ToTable("ZhuanZhengShen");
            });
            builder.Entity<PaymentShen>(b =>
            {
                b.ToTable("PaymentShen");
            });
        }
    }
}
